package com.web.listener;

import javax.servlet.annotation.WebListener;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionAttributeListener;
import javax.servlet.http.HttpSessionBindingEvent;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;
//@WebListener
public class MySessionListener  
implements HttpSessionListener,
                      HttpSessionAttributeListener{

	@Override
	public void sessionCreated(HttpSessionEvent event) {
		System.out.println("===1. 创建HttpSession....");
		HttpSession session = event.getSession();
		String sessionId = session.getId();
		System.out.println(sessionId);
	}

	@Override
	public void sessionDestroyed(HttpSessionEvent event) {
		System.out.println("===2.销毁HttpSession...");
		HttpSession session = event.getSession();
		String sessionId = session.getId();
		System.out.println(sessionId);
	}

	@Override
	public void attributeAdded(HttpSessionBindingEvent event) {
		System.out.println("===1.添加属性......");
		String name = event.getName();
		Object value = event.getValue();
		System.out.println(name+"---->"+value);
	}

	@Override
	public void attributeRemoved(HttpSessionBindingEvent event) {
		System.out.println("===2.移除属性......");
		String name = event.getName();
		Object value = event.getValue();
		System.out.println(name+"---->"+value);
	}

	@Override
	public void attributeReplaced(HttpSessionBindingEvent event) {
		System.out.println("===3.替换属性......");
		String name = event.getName();
		Object value = event.getValue();		
		System.out.println(name+"---->"+value);
	}

}
